<?php

namespace Model;

class usersProfile extends \Zend_Db_Table_Abstract
{
    /**
     * @var string
     */
    protected $_name = 'usersProfile';
    
    /**
     * @param int $userId
     * @param array $input name
     * @return int
     */
    public function insertUserProfile($userId, array $input)
    {   
        \Helper\array_isset($input, array('name'));
        
        $stmt = $this->getAdapter()->query(
        "INSERT INTO {$this->_name} SET
                userId = ?,
                name = ?;",
        array($userId,$input['name']));
            
        return $stmt->getDriverStatement()->insert_id;
    }
    
    /**
     * @param int $userId
     * @param array $select
     * @param string $whereColumn
     * @param mixed $whereValue
     * @return array
     */
    public function getUserProfile( $userId,
                                    array $select,
                                    $whereColumn = NULL,
                                    $whereValue = NULL)
    {
        $selectQuery = implode(',', $select);
        
        if ($whereColumn)
            $stmt = $this->getAdapter()->query(
            "SELECT {$selectQuery}
                    FROM {$this->_name}
                    WHERE `userId` = ? AND `{$whereColumn}` = ?
                    LIMIT 1;",
            array($userId, $whereValue));
        else
            $stmt = $this->getAdapter()->query(
            "SELECT {$selectQuery}
                    FROM {$this->_name}
                    WHERE `userId` = ?
                    LIMIT 1;",
            array($userId));
        
        return $stmt->fetch();
    }
}

# eof